#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
int main()
{

    int recv_fd, size;
    char buf[1024];
    struct sockaddr_in serv_addr, cli_addr;
    socklen_t cli_len = sizeof(cli_addr);
    recv_fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (recv_fd < 0)
    {
        perror("socket");
        exit(1);
    }

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(8080);
    serv_addr.sin_addr.s_addr = INADDR_ANY;

    bind(recv_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));

    size = recvfrom(recv_fd, buf, sizeof(buf), 0, (struct sockaddr *)&cli_addr, &cli_len);
    printf("recvfrom: %s\n", buf);
    printf("cli_addr: %s\n", inet_ntoa(cli_addr.sin_addr));
    printf("cli_port: %d\n", ntohs(cli_addr.sin_port));
    close(recv_fd);

    return 0;
}